package com.xcity.pomelo.response;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import com.alibaba.fastjson.annotation.JSONField;
import com.xcity.db.entity.Build;
import com.xcity.db.entity.Player;

import naga.x.net.impl.pomelo.PomeloMessage;
import naga.x.net.impl.pomelo.protocol.Message;

@Deprecated
@PomeloMessage(type = Message.Type.RESPONSE)
public class BuildListStatusResponse extends Response {
	
	private int health; // 风险值
	private List<BuildStatusRes> build;
	
	public static class BuildStatusRes extends BuildStatusResponse {
		public BuildStatusRes(Player owner, Build ref) {
			super(0, owner, ref);
		}
		@Override
		@JSONField(serialize = false)
		public short getCode() {
			return super.getCode();
		}
	}
	
	public BuildListStatusResponse(int serial, Player player) {
		super(serial);
		this.health = player.getRisk();
		List<Build> srcs = player.getBuildings().getBuildings();
		int size;
		if (srcs != null && (size = srcs.size()) > 0) {
			List<BuildStatusRes> list = new ArrayList<BuildStatusRes>(size);
			for (int i = 0; i < size; i++) {
				Build src = srcs.get(i);
				BuildStatusRes b = new BuildStatusRes(player, src);
				list.add(b);
			}
			this.build = list;
		} else {
			this.build = Collections.emptyList();
		}
	}

	public int getHealth() {
		return health;
	}

	public void setHealth(int health) {
		this.health = health;
	}

	public List<BuildStatusRes> getBuild() {
		return build;
	}

	public void setBuild(List<BuildStatusRes> build) {
		this.build = build;
	}
	
}
